package com.wang.wx.controller;

import com.wang.wx.common.Result;
import com.wang.wx.entity.req.RequestDto;
import com.wang.wx.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author wjh
 * @create 2024-08-05 10:44
 */
@Api(tags = "数据查询转换")
@RestController
@RequestMapping("/admin/system/query")
public class QueryController {
    
    @Resource
    private QueryService queryService;
    @Resource
    private TwitterUserService twitterUserService;
    @Resource
    private WxUserService wxUserService;
    @Resource
    private LyUserService lyUserService;
    @Resource
    private EmailUserService emailUserService;
    @Resource
    private IOExcel ioExcel;
    @Value("${path.output}")
    private String outputFilePath;
    
//    @ApiOperation(value = "数据查询")
//    @GetMapping("/query")
//    public String query(
//            @ApiParam(value = "微信账号") @RequestParam(required = false) String wxId,
//            @ApiParam(value = "邮箱") @RequestParam(required = false) String email,
//            @ApiParam(value = "领英账号") @RequestParam(required = false) String lyId,
//            @ApiParam(value = "推特账号") @RequestParam(required = false) String screenName,
//            @ApiParam(value = "手机号") @RequestParam(required = false) String phone
//    ) {
//        RequestDto requestDto = new RequestDto();
//        requestDto.setWxId(wxId);
//        requestDto.setEmail(email);
//        requestDto.setLyId(lyId);
//        requestDto.setPhone(phone);
//        requestDto.setScreenName(screenName);
//        queryService.complexQuery(requestDto);
//        return "hello";
//    }

    @ApiOperation(value = "邮箱转推特")
    @GetMapping("/emailToTwitter")
    public Result<String> emailToTwitter(@ApiParam(value = "输入导入模板的Excel文件路径") @RequestParam String file) throws Exception {
        String originalFilename;
        try (InputStream inputStream = Files.newInputStream(Paths.get(file))) {
            //获取file的文件名，不要前面的目录名
            originalFilename = file.substring(file.lastIndexOf("\\") + 1);
            ioExcel.emailToTwitterInputExcel(inputStream, originalFilename);
        } catch (Exception e) {
            return Result.fail();
        }
        return Result.ok("判定完成，判定结果文件在" + outputFilePath + originalFilename);
    }

    @ApiOperation(value = "手机转微信号")
    @GetMapping("/phoneToWx")
    public Result phoneToWx(@ApiParam(value = "输入导入模板的Excel文件路径") @RequestParam String file) {
        String originalFilename;
        try (InputStream inputStream = Files.newInputStream(Paths.get(file))) {
            //获取file的文件名，不要前面的目录名
            originalFilename = file.substring(file.lastIndexOf("\\") + 1);
            ioExcel.phoneToWxInputExcel(inputStream, originalFilename);
        } catch (Exception e) {
            return Result.fail();
        }
        return Result.ok("判定完成，判定结果文件在" + outputFilePath + originalFilename);
    }


    @ApiOperation(value = "手机转邮箱")
    @GetMapping("/phoneToEmail")
    public Result phoneToEmail(@ApiParam(value = "输入导入模板的Excel文件路径") @RequestParam String file) {
        String originalFilename;
        try (InputStream inputStream = Files.newInputStream(Paths.get(file))) {
            //获取file的文件名，不要前面的目录名
            originalFilename = file.substring(file.lastIndexOf("\\") + 1);
            ioExcel.phoneToEmailInputExcel(inputStream, originalFilename);
        } catch (Exception e) {
            return Result.fail();
        }
        return Result.ok("判定完成，判定结果文件在" + outputFilePath + originalFilename);
    }


    @ApiOperation(value = "手机转领英账号")
    @GetMapping("/phoneToLy")
    public Result phoneToLy(@ApiParam(value = "输入导入模板的Excel文件路径") @RequestParam String file) {
        String originalFilename;
        try (InputStream inputStream = Files.newInputStream(Paths.get(file))) {
            //获取file的文件名，不要前面的目录名
            originalFilename = file.substring(file.lastIndexOf("\\") + 1);
            ioExcel.phoneToLyInputExcel(inputStream, originalFilename);
        } catch (Exception e) {
            return Result.fail();
        }
        return Result.ok("判定完成，判定结果文件在" + outputFilePath + originalFilename);
    }


    @ApiOperation(value = "邮箱转领英账号")
    @GetMapping("/emailToLy")
    public Result emailToLy(@ApiParam(value = "输入导入模板的Excel文件路径") @RequestParam String file) {
        String originalFilename;
        try (InputStream inputStream = Files.newInputStream(Paths.get(file))) {
            //获取file的文件名，不要前面的目录名
            originalFilename = file.substring(file.lastIndexOf("\\") + 1);
            ioExcel.emailToLyInputExcel(inputStream, originalFilename);
        } catch (Exception e) {
            return Result.fail();
        }
        return Result.ok("判定完成，判定结果文件在" + outputFilePath + originalFilename);
    }
    
}
